package com.renzhebiao.lkang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.renzhebiao.lkang.comment.Need;
import com.renzhebiao.lkang.entity.OpusPO;
import com.renzhebiao.lkang.facade.OpusFacade;
import com.renzhebiao.lkang.master.ExecuteResult;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.OpusQuery;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 作品表 前端控制器
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@RestController
@RequestMapping("/opus")
@Api(tags = "作品展示")
public class OpusController {

    @Autowired
    private OpusFacade opusFacade;

    @ApiOperation(value = "新增作品展示", notes = "新增作品展示", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/add")
    @Need(token = true)
    public ExecuteResult<?> add(@RequestBody OpusPO po) {
        this.opusFacade.add(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "修改作品展示", notes = "修改作品展示", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/edit")
    @Need(token = true)
    public ExecuteResult<?> edit(@RequestBody OpusPO po) {
        this.opusFacade.edit(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "删除作品展示", notes = "删除作品展示", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/delete")
    @Need(token = true)
    public ExecuteResult<?> delete(@RequestBody Long id) {
        this.opusFacade.delete(id);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "查询作品展示列表", notes = "查询作品展示列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/list")
    public ExecuteResult<?> getOpusList(@RequestBody OpusQuery param) {
        return ExecuteResult.ok(this.opusFacade.getOpusList(param));
    }

    @ApiOperation(value = "查询作品展示单条", notes = "查询作品展示单条", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/get")
    public ExecuteResult<?> getOpus(@RequestBody Long id) {
        return ExecuteResult.ok(this.opusFacade.getOpus(id));
    }

    @ApiOperation(value = "分页查询作品展示", notes = "分页查询作品展示", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/page")
    public ExecuteResult<?> getOpusByPage(@RequestBody PaginationDTO<OpusQuery, Void> paging) {
        return ExecuteResult.ok(this.opusFacade.getOpusByPage(paging));
    }

}
